package com.yuchen.ishop.service.goods;

import com.yuchen.ishop.entity.GoodsImg;
import com.yuchen.jaxrs.Responses;
import com.yuchen.jaxrs.restclient.RestClientUtils;
import com.yuchen.utils.config.ConfigUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *
 */
@Service
public class GoodsImgRestClient {

    public GoodsImg get(Long id){
        String url = ConfigUtils.config.get("goodsimg_get");
        Map map = new HashMap(1);
        map.put("id",id);
        url =RestClientUtils.url(url,map);
        return RestClientUtils.get(GoodsImg.class, url);
    }

    public Responses insert(GoodsImg goodsImg){
        String url = ConfigUtils.config.get("goodsimg_insert");
        return RestClientUtils.post(Responses.class, goodsImg, url);
    }

    public Responses delete(Long id) {
        String url = ConfigUtils.config.get("goodsimg_delete");
        Map map = new HashMap(1);
        map.put("id",id);
        url =RestClientUtils.url(url,map);
        return RestClientUtils.delete(Responses.class, url);
    }

    public Responses changeGoodsImgType(Long id,String allIds) {
        String url = ConfigUtils.config.get("goodsimg_changeType");
        Map map = new LinkedHashMap(2);
        map.put("id",id);
        map.put("allIds",allIds);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.post(Responses.class,map, url);
    }

    public Responses showGoodsImg(Long goodsId) {
        String url = ConfigUtils.config.get("goodsimg_findByGoodsId");
        Map map = new HashMap(1);
        map.put("goodsId",goodsId);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.get(Responses.class,url);
    }

    public String getGoodsMainImg(Long  goodsId) {
        String url =  ConfigUtils.config.get("goodsimg_getMainImgByGoodsId");
        Map map = new HashMap(1);
        map.put("goodsId",goodsId);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.get(String.class,url);
    }

    public Responses deleteByGoodsId(Long goodsId) {
        String url =  ConfigUtils.config.get("goodsimg_deleteByGoodsId");
        Map map = new HashMap(1);
        map.put("goodsId",goodsId);
        url = RestClientUtils.url(url,map);
        return RestClientUtils.delete(Responses.class, url);
    }
}
